using Blog2025.Domain.Events;

namespace Blog2025.Domain.Entities;
public abstract class EntityBase
{
    private readonly List<IDomainEvent> _domainEvents = new();
    public Guid Id { get; set; }
    public string? Code { get; set; }// Stu24000001

    public bool IsActived { get; set; } = true;
    public bool IsDeleted { get; set; } = false;

    public DateTime CreatedAt { get; set; } = DateTime.UtcNow;
    public DateTime UpdatedAt { get; set; } = DateTime.UtcNow;

    public Guid CreatedBy { get; set; } = Guid.Empty;
    public Guid UpdatedBy { get; set; }= Guid.Empty;

    public int DisplayOrder { get; set; }

    public string? Remarks { get; set; }

        /// <summary>
    /// 获取领域事件（只读）
    /// </summary>
    public IReadOnlyCollection<IDomainEvent> DomainEvents => _domainEvents.AsReadOnly();

    /// <summary>
    /// 添加领域事件
    /// </summary>
    /// <param name="domainEvent">领域事件</param>
    protected void AddDomainEvent(IDomainEvent domainEvent)
    {
        _domainEvents.Add(domainEvent);
    }

    /// <summary>
    /// 清空领域事件
    /// </summary>
    public void ClearDomainEvents()
    {
        _domainEvents.Clear();
    }
}